const Koa = require("koa")
const { koaBody } = require("koa-body")

const cors = require("koa2-cors")
const logger = require("koa-logger")
const koaStatic = require("koa-static")
const koaJwt = require("koa-jwt")
const Router = require("@koa/router")



const db = require('./db')

db.init()

const app = new Koa()

app.use(cors());
app.use(koaJwt({
    secret: '2302B',
}).unless({
    path: [/^\/user\/login/, /^\/user\/register/],
}))
app.use(logger());
app.use(koaStatic(__dirname + "public"))

app.use(koaBody());

const router = new Router();
const user = require("./routes/user")
const goods = require("./routes/goods")

app.use(router.routes()).use(router.allowedMethods())
app.use(user.routes()).use(user.allowedMethods())
app.use(goods.routes()).use(goods.allowedMethods())


app.listen(8000)